/**
 * 
 */
package org.xtense.tests;

import java.text.MessageFormat;
import java.util.Iterator;

import org.xtense.engine.IConstants;
import org.xtense.engine.SimpleQueryParser;

/**
 * @author Owner
 * 
 */
public class ParserTest {

	public static void main(String args[]) {

		testQueryEngineFunction("/books");
		testQueryEngineFunction("//book[@show='yes']/title");

	}

	public static void testQueryEngineFunction(String xpath) {
		SimpleQueryParser parser = new SimpleQueryParser(2, xpath);

		// select elementPre sql
		String elemIn = MessageFormat.format(IConstants.Sql_IN, new Object[] {
				IConstants.Element_Pre, parser.getPathQuery() });
		String docidEq = MessageFormat.format(IConstants.Sql_Int_Equal,
				new Object[] { IConstants.Document_ID, 2 });

		getResult(elemIn, docidEq);
	}

	private static void getResult(String elemIn, String s) {
		for (Iterator<Integer> iterator = IConstants.AETPtables.keySet().iterator(); iterator
				.hasNext();) {
			int i = iterator.next().intValue();
			String sql = MessageFormat.format(IConstants.Sql_Select_Two,
					new Object[] { "*", IConstants.AETPtables.get(i), elemIn, s });
			System.out.println(sql);

		}

	}

}
